# -*- encoding=utf8 -*-
"""
RedFlag-TC0000116  （拍摄进入装饰页）贴纸功能
新增贴纸场景
删除贴纸场景
更换贴纸场景
新增多个贴纸并移动场景
贴纸缩放场景
"""
__author__ = "ldm"

import sys
import os

# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *

auto_setup(__file__)
shooter = CameraVideoShooter()

log("--------------------------------新增贴纸场景--------------------------------------")
"""
拍摄视频进入装饰页
点击贴纸
添加贴纸
断言
"""

shooter.enter_photography_decoration_page()
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_effect)
shooter.assert_image_exists(r"tpl1749611647587.png", "断言失败，预期图片并未出现", record_pos=(-0.004, -0.394), resolution=(1224, 2700))

log("--------------------------------删除贴纸场景--------------------------------------")
"""
点击贴纸
点击删除
断言
"""

touch((0.5,0.5))
shooter.click_element(decoration_page_sticker_delete)
shooter.assert_image_not_exists(r"tpl1749611647587.png", "断言失败，预期图片出现", record_pos=(-0.004, -0.394), resolution=(1224, 2700))

log("--------------------------------更换贴纸场景--------------------------------------")
"""
点击贴纸
点击删除
断言
"""

shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_effect)
touch((0.5,0.5))
shooter.click_element(decoration_page_sticker_replace)
shooter.click_element(decoration_page_sticker_effect[1])
shooter.assert_image_exists(r"tpl1749612185355.png", "断言失败，预期图片并未出现", record_pos=(0.005, -0.002), resolution=(1224, 2700))


log("--------------------------------新增多个贴纸并移动场景--------------------------------------")
"""
将贴纸移动到(0.5,0.5), (0.1,0.15)，左上角
点击贴纸
点击索引为1的贴纸分类
添加索引为0的贴纸
将贴纸移动到(0.5,0.5), (0.5,0.15))中上
点击贴纸
点击索引为2的贴纸分类
添加索引为0的贴纸
将贴纸移动到(0.5,0.5), (0.8,0.15))右上
点击贴纸
点击索引为3的贴纸分类
添加索引为0的贴纸
将贴纸移动到(0.5,0.5), (0.1,0.5))左边
点击贴纸
点击索引为4的贴纸分类
添加索引为0的贴纸
将贴纸移动到(0.5,0.5), (0.8,0.5))右边
点击贴纸
添加索引为0的贴纸
将贴纸移动到(0.5,0.5), (0.8,0.5))左下
点击贴纸
点击索引为1的贴纸分类
添加索引为1的贴纸
将贴纸移动到(0.5,0.5), (0.8,0.5))中下
点击贴纸
点击索引为2的贴纸分类
添加索引为2的贴纸
将贴纸移动到(0.5,0.5), (0.8,0.5))右下
点击贴纸
点击索引为2的贴纸分类
添加索引为2的贴纸
断言
"""

shooter.swipe_screen((0.5,0.5), (0.1,0.15))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[1])
shooter.click_element(decoration_page_sticker_effect[0].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.5,0.15))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[2])
shooter.click_element(decoration_page_sticker_effect[0].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.8,0.15))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[3])
shooter.click_element(decoration_page_sticker_effect[0].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.1,0.5))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[4])
shooter.click_element(decoration_page_sticker_effect[0].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.8,0.5))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_effect[1].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.1,0.8))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[1])
shooter.click_element(decoration_page_sticker_effect[1].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.5,0.8))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[2])
shooter.click_element(decoration_page_sticker_effect[2].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.swipe_screen((0.5,0.5), (0.8,0.8))
shooter.click_element(decoration_page_sticker)
shooter.click_element(decoration_page_sticker_classification[3])
shooter.click_element(decoration_page_sticker_effect[3].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
shooter.assert_image_exists(r"tpl1749969097995.png", "断言失败，预期图片并未出现", record_pos=(-0.006, -0.024), resolution=(1224, 2700), threshold=0.80)



log("--------------------------------贴纸缩放场景--------------------------------------")
"""
点击上一步
点击确认
点击✓进入装饰页
点击贴纸
添加贴纸
断言
"""

shooter.click_element(decoration_page_return_button)
shooter.click_element(decoration_page_return_confirm)
sleep(2.0)
shooter.click_element(shooting_page_next_button)
shooter.click_element(poco("cn.migu.video.clip.walle:id/clip_et_sticker_iv"))
shooter.click_element(decoration_page_sticker_effect[1].child("cn.migu.video.clip.walle:id/clip_bg_item_img"))
photo1 = shooter.capture_screenshot("TC0000116A.png")
touch((0.5,0.5))
shooter.swipe_from_template_to_point(r"tpl1749629310644.png", record_pos=(0.122, 0.12), resolution=(1224, 2700), target_pos=(0.8,0.85))
photo2 = shooter.capture_screenshot("TC0000116B.png")
shooter.assert_images_not_equal(photo1, photo2, "断言失败，两张图片对比一致说明缩放未成功", threshold=0.95)

# 关闭应用
stop_app(UGC_package_name)
